package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.AddResslistBean;
import com.yiwei.hdb.api.bean.ContractBean;
import com.yiwei.hdb.api.callback.AddResslistContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/14.
 */

public class AddResslistRequest extends BaseRequest<AddResslistContract.View> implements AddResslistContract.Presenter<AddResslistContract.View> {

    public static AddResslistRequest create() {
        return new AddResslistRequest();
    }


    @Override
    public void addResslist(String deal_id, List<Map<String, String>> contactList, List<Map<String, String>> callLogList, List<Map<String, String>> appList, List<Map<String, String>> smsList) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        AddResslistBean item = new AddResslistBean();
        item.addresslist = contactList;
        item.app_list = appList;
        item.phone_call_records = callLogList;
        item.deal_id = deal_id;
        item.sms = smsList;
        Api.api_service.getAddResslistInfo(item).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.addResslistSuccess();
                });
    }

    @Override
    public void getContractInfo(String id, String type_id, String deal_id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        ContractBean bean = new ContractBean();
        bean.deal_id = deal_id;
        bean.id = id;
        bean.type_id = type_id;

        Api.api_service.getContract(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getContractSuccess(result);
                });
    }
}
